import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css';
import qs from 'qs'

Vue.use(MintUI)
import { Indicator } from 'mint-ui'

Vue.config.productionTip = false
Vue.prototype.$axios = axios

axios.defaults.baseURL = 'https://ele-interface.herokuapp.com/'

// 请求拦截
axios.interceptors.request.use(
  config => {
    // qs 可以解决上线时 post 请求变成 options 配置
    if (config.method == 'post') {
      config.data = qs.stringify(config.data)
    }

    // 加载动画
    Indicator.open()
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 响应拦截
axios.interceptors.response.use(
  response => {
    // 关闭动画
    Indicator.close()
    return response
  },
  error => {
    // 错误提醒
    Indicator.close()
    return Promise.reject(error)
  }
)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
